/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests.UserManagement;

import Utilities.PermissionsConstants;

/**
 * Instances of this class are used by the user interface when a request to create
 * a new user is sent to the users management service(s).
 *
 * @author Angel Sanadinov
 */
public class UserCreateRequest extends UserManagementRequest
{
    private String username;        //the name of the new user
    private String password;        //the password of the new user
    private int accountLevel;       //user account level

    /**
     * No-argument constructor. <br><br>
     * Only the requested action is set (create).
     */
    public UserCreateRequest()
    {
        super.setRequestedAction(PermissionsConstants.ACTION_USER_CREATE);
    }

    /**
     * Constructs the request object using the supplied data for user creation.
     *
     * @param requestorId the id the of the user that requested the action
     * @param username the username of the new user
     * @param password the password of the new user
     * @param accountLevel account level of the new user
     */
    public UserCreateRequest(int requestorId, String username, String password, int accountLevel)
    {
        super.setRequestorId(requestorId);
        super.setRequestedAction(PermissionsConstants.ACTION_USER_CREATE);
        this.username = username;
        this.password = password;
        this.accountLevel = accountLevel;
    }

    /**
     * Retrieves the name of the new user.
     *
     * @return the new user's name
     */
    public String getUsername()
    {
        return username;
    }

    /**
     * Retrieves the password of the new user.
     *
     * @return the new user's password
     */
    public String getPassword()
    {
        return password;
    }

    /**
     * Retrieves the account level of the new user.
     *
     * @return the new user's account level
     */
    public int getAccountLevel()
    {
        return accountLevel;
    }

    /**
     * Sets the account level of the new user.
     *
     * @param accountLevel the new user's account level
     */
    public void setAccountLevel(int accountLevel)
    {
        this.accountLevel = accountLevel;
    }

    /**
     * Sets the name of the new user.
     *
     * @param username the new user's name
     */
    public void setUsername(String username)
    {
        this.username = username;
    }

    /**
     * Sets the password of the new user.
     * 
     * @param password the new user's password
     */
    public void setPassword(String password)
    {
        this.password = password;
    }

    /**
     * Checks the validity of the object. <br><br>
     *
     * This object is valid only when all data required for the request is valid.
     *
     * @return <code>true</code> if the object is valid or <code>false</code> otherwise
     */
    @Override
    public boolean isValid()
    {
        if(username != null && !username.trim().equals("") && password != null
                && !password.trim().equals("") && isRequestorIdValid())
            return true;
        else
            return false;
    }

    /**
     * Returns a textual representation of the object. <br>
     *
     * It is in the form: "ClassName: (affectedUserId,username,accountLevel)".
     *
     * @return the object represented as a String
     */
    @Override
    public String toString()
    {
        return UserCreateRequest.class.getSimpleName() + ": (" + getAffectedUserId()
                + "," + username + "," + accountLevel + ")";
    }
}
